﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;

namespace WMI.NET.CIM
{
    /// <summary>
    /// The CIM_PhysicalMemory class represents low-level memory devices, such as SIMMS, DIMMs, raw memory chips, and so on. 
    /// </summary>
    public class CIM_PhysicalMemory : CIM_Chip
    {

        private string _BankLabel;
        private Nullable<UInt64> _Capacity;
        private Nullable<UInt16> _DataWidth;
        private Nullable<UInt32> _InterleavePosition;
        private Nullable<UInt16> _MemoryType;
        private Nullable<UInt32> _PositionInRow;
        private Nullable<UInt32> _Speed;
        private Nullable<UInt16> _TotalWidth;

        /// <summary>
        /// Labeled bank in which the memory is located. For example, "Bank 0" or "Bank A".
        /// </summary>
        public string BankLabel { get { return _BankLabel; } }

        /// <summary>
        /// Total capacity of the physical memory, in bytes.
        /// </summary>
        public Nullable<UInt64> Capacity { get { return _Capacity; } }

        /// <summary>
        /// Data width of the physical memory, in bits. A data width of 0 (zero) , and a total width of 8, indicates that the memory is solely used to provide error correction bits.
        /// </summary>
        public Nullable<UInt16> DataWidth { get { return _DataWidth; } }

        /// <summary>
        /// Position of the physical memory in an interleave. A value of 0 indicates non-interleaved, 1 indicates the first position, 2 indicates the second position, and so on. For example, in a 2:1 interleave, a value of 1 indicates that the memory is in the even position.
        /// </summary>
        public Nullable<UInt32> InterleavePosition { get { return _InterleavePosition; } }

        /// <summary>
        /// Type of physical memory.
        /// </summary>
        public Nullable<UInt16> MemoryType { get { return _MemoryType; } } //TODO enum

        /// <summary>
        /// Position of the physical memory in a row. For example, if it takes two 8-bit memory devices to form a 16-bit row, then a value of 2 indicates that the memory is the second device. A value of 0 is an invalid value for this property.
        /// </summary>
        public Nullable<UInt32> PositionInRow { get { return _PositionInRow; } }

        /// <summary>
        /// Speed of the physical memory, in nanoseconds.
        /// </summary>
        public Nullable<UInt32> Speed { get { return _Speed; } }

        /// <summary>
        /// Total width, in bits, of the physical memory, including check or error correction bits. If there are no error correction bits, the value in this property should match that specified for the DataWidth property.
        /// </summary>
        public Nullable<UInt16> TotalWidth { get { return _TotalWidth; } }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="mbo"></param>
        public CIM_PhysicalMemory(ManagementBaseObject mbo)
            : base(mbo)
        {
            _BankLabel = mbo.GetStringValue("BankLabel");
            _Capacity = mbo.GetUlongValue("Capacity");
            _DataWidth = mbo.GetUshortValue("DataWidth");
            _InterleavePosition = mbo.GetUIntValue("InterleavePosition");
            _MemoryType = mbo.GetUshortValue("MemoryType");
            _PositionInRow = mbo.GetUIntValue("PositionInRow");
            _Speed = mbo.GetUIntValue("Speed");
            _TotalWidth = mbo.GetUshortValue("TotalWidth");
        }

    }
}
